package user;

import Dao.communityDao;
import Dao.communityDaoImpl;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.sql.SQLException;
@WebServlet(value = "/deleteHealthInformation")
public class deleteInformationServlet extends HttpServlet {
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        communityDao dao=new communityDaoImpl();
        String message=null;
        int health_id=0;
        String health_idParam=request.getParameter("health_id");
        if(health_idParam==null||health_idParam.isEmpty()){
            message="id不能为空";
            request.setAttribute("message",message);
            request.getRequestDispatcher("/WEB-INF/user/deleteHealthInformation.jsp").forward(request,response);
        }
        else {
            try{
                health_id=Integer.parseInt(health_idParam);
                int res=dao.deleteHealthByHealthId(health_id);
                if(res>0){
                    message="删除成功";
                    request.setAttribute("message",message);
                    request.getRequestDispatcher("/WEB-INF/user/deleteHealthInformation.jsp").forward(request,response);
                }
                else{
                    message="删除失败";
                    request.setAttribute("message",message);
                    request.getRequestDispatcher("/WEB-INF/user/deleteHealthInformation.jsp").forward(request,response);
                }

            } catch (SQLException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
